package s08.ch10.homework;

import java.math.BigDecimal;
import java.math.RoundingMode;

public class Sedan extends Car {
	private Integer lenght;

	public Sedan(String color, BigDecimal price, Integer lenght) {
		super(color, price);
		setLenght(lenght);
	}

	public Integer getLenght() {
		return lenght;
	}

	public void setLenght(Integer lenght) {
		this.lenght = lenght;
	}

	public BigDecimal getDiscountedPrice() {
		if (getLenght() >= 4) {
			BigDecimal cena = getPrice();
			return cena;
		} else {
			double discountPercent = 0.05;
			BigDecimal decimalDiscountPercent = new BigDecimal(
					Double.toString(discountPercent));
			BigDecimal decimalSubtotal = getPrice();
			decimalSubtotal = decimalSubtotal
					.setScale(-2, RoundingMode.HALF_UP);
			BigDecimal discountAmount = decimalSubtotal
					.multiply(decimalDiscountPercent);
			BigDecimal discount = decimalSubtotal.subtract(discountAmount);
			return discount;
		}

	}
}
